Text wrapping, also known as line wrapping, word wrapping or line breaking, is breaking a section of text into lines so that it will fit into the available width of a page, window or other display area. In text display, line wrap is continuing on a new line when a line is full, so that each line fits into the viewable area without overflowing, allowing text to be read from top to bottom without any horizontal scrolling. Word wrap is the additional feature of most , word processors, and , of breaking lines between words rather than within words, where possible. Word wrap makes it unnecessary to Hard coding newline delimiters within paragraphs, and allows the display of text to adapt flexibly and dynamically to displays of varying sizes.
Alternatively, "soft return" can mean an intentional, stored line break that is not a paragraph break. For example, it is common to print postal addresses in a multiple-line format, but the several lines are understood to be a single paragraph. Line breaks are needed to divide the words of the address into lines of the appropriate length.
In the contemporary graphical word processors Microsoft Word and Libreoffice Writer, users are expected to type a carriage return () between each paragraph. Formatting settings, such as first-line indentation or spacing between paragraphs, take effect where the carriage return marks the break. A non-paragraph line break, which is a soft return, is inserted using or via the menus, and is provided for cases when the text should start on a new line but none of the other side effects of starting a new paragraph are desired.
In text-oriented markup languages, a soft return is typically offered as a markup tag. For example, in HTML there is a <br> tag that has the same purpose as the soft return in word processors described above.
The Unicode character set provides a line separator character as well as a paragraph separator to represent the semantics of the soft return and hard return.
A word without hyphens can be made wrappable by having in it. When the word isn't wrapped (i.e., isn't broken across lines), the soft hyphen isn't visible. But if the word is wrapped across lines, this is done at the soft hyphen, at which point it is shown as a visible hyphen on the top line where the word is broken. (In the rare case of a word that is meant to be wrappable by breaking it across lines but without making a hyphen ever appear, a zero-width space is put at the permitted breaking point(s) in the word.)
Sometimes word wrap is undesirable between adjacent words. In such cases, word wrap can usually be blocked by using a hard space or non-breaking space between the words, instead of regular spaces.
Under certain circumstances, however, word wrapping is not desired. For instance,
Most existing word processors and typesetting software cannot handle either of the above scenarios.
CJK characters punctuation may or may not follow rules similar to the above-mentioned special circumstances. It is up to line breaking rules in CJK.
SpaceLeft := LineWidth
for each Word in Text
if (Width(Word) + SpaceWidth) > SpaceLeft
insert line break before Word in Text
SpaceLeft := LineWidth - Width(Word)
else
SpaceLeft := SpaceLeft - (Width(Word) + SpaceWidth)
Where LineWidth is the width of a line, SpaceLeft is the remaining width of space on the line to fill, SpaceWidth is the width of a single space character, Text is the input text to iterate over and Word is a word in this text.
The greedy algorithm for line-breaking predates the dynamic programming method outlined by Donald Knuth in an unpublished 1977 memo describing his TeX typesetting system. Reprinted in . and later published in more detail by Knuth & Plass (1981).
|
|